package com.hlhj.funlike_businessqzxd.moudle;


import android.content.Context;

import com.example.mymvp.mvp.BaseModule;
import com.hlhj.funlike_businessqzxd.api.Apis;
import com.hlhj.funlike_businessqzxd.api.BaseObser;
import com.hlhj.funlike_businessqzxd.bean.FoodDetailBean;
import com.hlhj.funlike_businessqzxd.bean.FoodTypeBean;
import com.hlhj.funlike_businessqzxd.bean.MsgBean;
import com.hlhj.funlike_businessqzxd.bean.UpImgBean;
import com.lzy.okgo.model.Response;

import java.io.File;
import java.util.List;

public class AddCommentyMoudle implements BaseModule {
    public interface getEidtFoodDetail {
        void loadFoodDetai(FoodDetailBean.DataBean dataBean);

        void loadUpFoodImgResult(UpImgBean.DataBean dataBean);

        void loadFoodType(List<FoodTypeBean.DataBean> dataBeans);

        void loadEditFoodResult(String msg);
    }

    public getEidtFoodDetail listener;

    public void setListener(getEidtFoodDetail listener) {
        this.listener = listener;
    }

    public void LoadFoodDetail(Context context, int id) {
        Apis.INSTANCE.FoodDetail(id)
                .subscribe(new BaseObser<Response<FoodDetailBean>>(context) {
                    @Override
                    public void httpSuccess(Response<FoodDetailBean> foodDetailBeanResponse) {
                        if (listener != null) {
                            listener.loadFoodDetai(foodDetailBeanResponse.body().getData());
                        }
                    }
                });
    }

    public void LoadUpFoodImgResult(Context context, File image) {
        Apis.INSTANCE.UpFoodImg(image)
                .subscribe(new BaseObser<Response<UpImgBean>>(context) {
                    @Override
                    public void httpSuccess(Response<UpImgBean> upImgBeanResponse) {
                        if (listener != null) {
                            listener.loadUpFoodImgResult(upImgBeanResponse.body().getData());
                        }
                    }
                });
    }

    //商品类型列表
    public void LoadFoodType(Context context) {
        Apis.INSTANCE.GetGoodTypeList()
                .subscribe(new BaseObser<Response<FoodTypeBean>>(context) {
                    @Override
                    public void httpSuccess(Response<FoodTypeBean> foodTypeBeanResponse) {
                        if (listener != null) {
                            listener.loadFoodType(foodTypeBeanResponse.body().getData());
                        }
                    }
                });
    }

    //修改商品
    public void LoadEditFoodResult(Context context,int id,String goods_name,int type_id,String price,String details,
                                   int is_discount,String discount,int is_restrictions,int num,int is_sell,String photos,String attr,String stock){
        Apis.INSTANCE.EditFood(id,goods_name,type_id,price,details,is_discount,discount,is_restrictions,num,is_sell,photos,attr,stock)
                .subscribe(new BaseObser<Response<MsgBean>>(context) {
                    @Override
                    public void httpSuccess(Response<MsgBean> msgBeanResponse) {
                        if (listener!=null){
                            listener.loadEditFoodResult(msgBeanResponse.body().getMsg());
                        }
                    }
                });
    }
    //添加商品
    public void LoadAddFood(Context context,String goods_name,int type_id,String price,String details,
                            int is_discount,String discount,int is_restrictions,int num,int is_sell,String photos,String attr,String stock){
        Apis.INSTANCE.AddFood(goods_name,type_id,price,details,is_discount,discount,is_restrictions,num,is_sell,photos,attr,stock)
                .subscribe(new BaseObser<Response<MsgBean>>(context) {
                    @Override
                    public void httpSuccess(Response<MsgBean> msgBeanResponse) {
                        if (listener!=null){
                            listener.loadEditFoodResult(msgBeanResponse.body().getMsg());
                        }
                    }
                });
    }
}
